package com.elitesland.b2c.tms.repo;

import com.elitesland.b2c.tms.entity.QTmsFareTmplAreaDO;
import com.elitesland.b2c.tms.entity.TmsFareTmplAreaDO;
import com.querydsl.jpa.impl.JPAQueryFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>
 * 功能说明
 * </p>
 *
 * @author fred
 * @since 2021-02-04 09:44:01
 */
@Repository
public class TmsFareTmplAreaRepoProc {

    @Autowired
    private JPAQueryFactory jpaQueryFactory;

    private final QTmsFareTmplAreaDO qTmsFareTmplAreaDO = QTmsFareTmplAreaDO.tmsFareTmplAreaDO;

    /**
     * 根据模板ID删除地区信息
     *
     * @param tmsFareTmplId 模板ID
     */
    public void deleteByTmsFareTmplId(Long tmsFareTmplId) {
        jpaQueryFactory.delete(qTmsFareTmplAreaDO)
                .where(qTmsFareTmplAreaDO.tmsFareTmplId.eq(tmsFareTmplId))
                .execute();
    }

    /**
     * 根据模板ID查询模板地区信息
     *
     * @param tmsFareTmplId 模板ID
     * @return 模板地区信息
     */
    public List<TmsFareTmplAreaDO> queryByTmsFareTmplId(Long tmsFareTmplId) {
        return jpaQueryFactory.select(qTmsFareTmplAreaDO)
                .from(qTmsFareTmplAreaDO)
                .where(qTmsFareTmplAreaDO.tmsFareTmplId.eq(tmsFareTmplId))
                .fetch()
                ;
    }

    /**
     * 根据模板ID查询模板地区信息
     *
     * @param tmsFareTmplIds 模板ID
     * @return 模板地区信息
     */
    public List<TmsFareTmplAreaDO> queryByTmsFareTmplId(List<Long> tmsFareTmplIds) {
        return jpaQueryFactory.select(qTmsFareTmplAreaDO)
                .from(qTmsFareTmplAreaDO)
                .where(qTmsFareTmplAreaDO.tmsFareTmplId.in(tmsFareTmplIds))
                .fetch()
                ;
    }
}